﻿@using Smartstore.Utilities

@functions{
    private DateTime? Value
    {
        get
        {
            DateTime? value = null;
            if (ViewData.Model != null)
            {
                value = Convert.ToDateTime(ViewData.Model, System.Globalization.CultureInfo.CurrentCulture);
            }
            return value;
        }
    }

    private string CssClass
    {
        get
        {
            var cls = "input-group date datetimepicker-group flex-nowrap";

            if (ViewData.ContainsKey("size"))
            {
                cls += " input-group-" + ViewData["size"].Convert<string>();
            }

            return cls;
        }
    }
}

@{
    var id = Html.IdForModel();
    var value = string.Empty;
    if (Value.HasValue && Value.Value > DateTime.MinValue)
    {
        value = Value.Value.ToShortTimeString();
    }

    var attributes = new AttributeDictionary().Merge(ConvertUtility.ObjectToDictionary(ViewData["htmlAttributes"] ?? new object()));
}

<div class="input-group date datetimepicker-group" id="@id-parent" data-date="@value" data-target-input="nearest">
    <input asp-for="@Model"
           attrs="attributes"
           value="@value"
           type="text"
           class="datetimepicker-input edit-control"
           data-editor="time"
           data-target="#@(id)-parent"
           data-format="LT"
           data-use-current="true" />

    <div class="input-group-append input-group-addon" data-target="#@(id)-parent" data-toggle="datetimepicker">
        <span class="input-group-text"><i class="far fa-clock"></i></span>
    </div>
</div>
